package com.jl.Button;


import com.jl.config.WeiXinSignUtil;
import com.jl.pojo.*;
import com.jl.util.JsapiTicketUnit;

/**
 * 描述：自定义button
 * author:yulin
 * Create date 2020-2-7 20:29
 */
public class WeiXinButton {
    public static void main (String [] args){

        //获取access_token
        AccessToken accesstoken= JsapiTicketUnit.getAccessToken(WeiXinSignUtil.appid,WeiXinSignUtil.appSecret);

        if(null!=accesstoken) {
            //创建菜单
           int a= JsapiTicketUnit.createMenu(getMenu(), accesstoken.getToken());

           if(a!=0){

               System.out.println("创建自定义菜单失败！");

           }
        }

    }



    public static Menu getMenu() {

        //创建二级菜单
        //如果二级菜单并没有一级菜单的话
        CommonButton btn11 = new CommonButton();
        btn11.setName("左面菜单");
        btn11.setType("click");
        btn11.setKey("11");

        CommonButton btn21=new CommonButton();
        btn21.setName("中间菜单");
        btn21.setType("click");
        btn21.setKey("21");

        CommonButton btn31=new CommonButton();
        btn31.setName("右面子菜单");
        btn31.setType("view");
        btn31.setUrl("https://open.com.jl.qq.com/connect/oauth2/authorize?appid=wx41c9f671d9c6355f&redirect_uri=http%3a%2f%2f39.105.65.69%2ftext1&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect");

        CommonButton btn32=new CommonButton();
        btn32.setName("测试");
        btn32.setType("click");
        btn32.setKey("32");

        //创建一级菜单
//        ComplexButton mainBtn2=new ComplexButton();
//        mainBtn2.setName("右面菜单");
//        mainBtn2.setSub_button(new CommonButton[]{btn31,btn32});

        Menu menu = new Menu();
//        menu.setButton(new Button[] {btn11, btn21,mainBtn2 });

        return menu;
    }


}
